<template>
	<view class="wrap">
        <view class="login-wrap">
            <view class='good'>
                <span class="code" @click="code">获取验证码</span>
                <input
                type="text"
                class="tel a"
                placeholder="请输入手机号"
                v-model="codeData.tel"
                />
            </view>
            <input
            type="password"
            class="password"
            placeholder="请输入验证码"
            v-model="codeData.password"
            />	
            <view class="btn">
                <button type="primary" class="login_btn" @click='register'>注册</button>
            </view>
        </view>
    </view>
</template>

<script>
	export default {
		data() {
			return {
                a_url:'http://v3-a.xgwl.net.cn',
                codeData:{
                    tel:'13545654131',
                    password:''
                },
			};
		},
		methods: {
            code(){
                var xml = new XMLHttpRequest();
                xml.open("get", this.a_url + "/cGetTelCodeToRegister?"+'tel='+this.codeData.tel);
                xml.send(null);
                xml.onreadystatechange = () => {
                    if (xml.readyState == 4) {
                        let res = JSON.parse(xml.responseText);
                        if(res.code == 200){
                            uni.showToast({
                                icon:"none",
                                title: '获取验证码成功',
                                duration: 2000
                            });
                        }else{
                            let text = res.data.split(':')[1]
                            uni.showToast({
                                icon:"none",
                                title: text,
                                duration: 2000
                            });
                        }
                    }
                }
            },
			register(){
                if(this.codeData.tel == '' || this.codeData.password == ''){
                    uni.showToast({
                        icon:"none",
                        title: '手机号和验证码不能为空',
                        duration: 2000
                    });
                }else{
                    var xml = new XMLHttpRequest();
                    xml.open("get", this.a_url + "/cTelCodeRegister?"+'tel='+this.codeData.tel+"&code="+this.codeData.password);
                    xml.send(null);
                    xml.onreadystatechange = () => {
                        if (xml.readyState == 4) {
                            let res = JSON.parse(xml.responseText);
                            if(res.code == 200){
                                uni.showToast({
                                    icon:"none",
                                    title: '注册成功',
                                    duration: 2000
                                });
                            }else{
                                let text = res.data.split(':')[1]
                                uni.showToast({
                                    icon:"none",
                                    title: text,
                                    duration: 2000
                                });
                            }
                        }
                    }
                }
                
            },
            
		},
		onLoad(){
		
		}
	}
</script>
<style lang="less">
    good{
        position: relative;
    }
    .code{
        position:absolute;
        right: 40px;
        z-index: 9999;
    }
	.wrap {
		height: 100vh;
		display: flex;
		justify-content: center;

		background-color: #fff;

		.login-wrap {
			margin-top: 50%;
			width: 80%;

		input {
			width: 100%;
			border-bottom: 1px solid #0081ff;
		}
    
		.a{
			margin-bottom: 20px;
		}
    .btn {
      display: flex;
      justify-content: center;
        .login_btn {
            width: 300px;
            border-radius: 35px;
            margin-top: 10px;
        }
	}
    .register {
      display: flex;
      justify-content: space-between;
      margin-bottom: 30px;
      color: #0081ff;
	  margin-top: 40rpx;
      .zhuce {
        font-size: 12px;
      }

      .mima {
        font-size: 12px;
      }
    }
  }
}
.twoRadio{
	margin-left: 40rpx;
}
.pcMoble{
	border-bottom: 1px solid #0081ff;
	width: 100%;
	height: 70rpx;
	margin-top: 20rpx;
}
.serStyle{
	margin-top: 20rpx;
	height: 64rpx;
	border-bottom: 1px solid #0081ff;
}
.serStyle-all{
	text-align: center;
	font-size: 30rpx;
}
</style>
